package com.gmail.viktor.yuryev.model;


import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Viktor Yuryev on 4/10/2014.
 */
public class ServerDetails /*implements PersistentStateComponent<Element>*/ {
    private int port;
    private String host;
    private String login;
    private String password;

    private String serverHome;

    private List<Link> mapping = new ArrayList<Link>();


    public ServerDetails() {
    }

    public String getSudoPrefix() {
        return sudoPrefix;
    }

    public void setSudoPrefix(String sudoPrefix) {
        this.sudoPrefix = sudoPrefix;
    }

    private String sudoPrefix;

    public String getServerHome() {
        return serverHome;
    }

    public void setServerHome(String serverHome) {
        this.serverHome = serverHome;
    }


    public ServerDetails(String host, String login, String password, int port) {
        this.port = port;
        this.host = host;
        this.login = login;
        this.password = password;
    }


    public ServerDetails clone() {
        ServerDetails serverDetails = new ServerDetails(host, login, password, port);
        serverDetails.setServerHome(serverHome);
        serverDetails.mapping = new ArrayList<Link>(mapping);
        serverDetails.setSudoPrefix(sudoPrefix);
        return serverDetails;
    }

    public void addLink(Path local, Path remote) {
        mapping.add(new Link(local, remote));
    }

    public void addLink(String local, String remote) {
        mapping.add(new Link(Paths.get(local), Paths.get(remote)));
    }

    public void setMapping(List<Link> mapping) {
        this.mapping = mapping;
    }


    public List<Link> getMapping() {
        return new ArrayList<Link>(mapping);
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ServerDetails that = (ServerDetails) o;

        if (port != that.port) return false;
        if (host != null ? !host.equals(that.host) : that.host != null) return false;
        if (login != null ? !login.equals(that.login) : that.login != null) return false;
        if (mapping != null ? !mapping.equals(that.mapping) : that.mapping != null) return false;
        if (password != null ? !password.equals(that.password) : that.password != null) return false;
        if (serverHome != null ? !serverHome.equals(that.serverHome) : that.serverHome != null) return false;
        if (sudoPrefix != null ? !sudoPrefix.equals(that.sudoPrefix) : that.sudoPrefix != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = port;
        result = 31 * result + (host != null ? host.hashCode() : 0);
        result = 31 * result + (login != null ? login.hashCode() : 0);
        result = 31 * result + (password != null ? password.hashCode() : 0);
        result = 31 * result + (sudoPrefix != null ? sudoPrefix.hashCode() : 0);
        result = 31 * result + (serverHome != null ? serverHome.hashCode() : 0);
        result = 31 * result + (mapping != null ? mapping.hashCode() : 0);
        return result;
    }


    @Override
    public String toString() {
        return "ServerDetails{" +
                "port=" + port +
                ", host='" + host + '\'' +
                ", login='" + login + '\'' +
                ", password='" + password + '\'' +
                ", sudoPrefix='" + sudoPrefix + '\'' +
                ", serverHome='" + serverHome + '\'' +
                ", map=" + mapping +
                '}';
    }
}
